$(function () {
    $('input').iCheck({
        checkboxClass: 'icheckbox_square-blue',
        radioClass: 'iradio_square-blue',
        increaseArea: '20%' /* optional */
    });

    $('.imgcode').click(function () {
        var url = ctx + "captcha/captchaImage?type=" + captchaType + "&s=" + Math.random();
        $(".imgcode").attr("src", url);
    });

    $('form').bootstrapValidator({
        message: 'This value is not valid',
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            name: {
                message: '用户名验证失败',
                validators: {
                    notEmpty: {
                        message: '用户名不能为空'
                    }
                }
            },
            password: {
                validators: {
                    notEmpty: {
                        message: '请输入密码'
                    }
                }
            }
        }
    });
});

$("#login").click(function () {
    var name = $("#name").val()
    var password = $("#password").val();
    var validateCode = $("input[name='vcode']").val();
    if (name == '' || name == null) {
        return
    }
    if (password == '' || password == null) {
        return
    }
    var loading = layer.msg('正在验证账户信息', {
        icon: 16
        ,shade: 0.01
    });
    var data = {
        loginName: name,
        password: password,
        validateCode: validateCode
    }
    request('/sys/login', 1, data, function (data) {
        // 判断图形验证码的
        if (data == null || data == '') {
            $('.imgcode').click();
            layer.msg("验证码错误！", {icon: 5})
            return
        }
        layer.close(loading)
        if (data.code == 0) {
            location.href = "/sys/index"
        } else if (data.code == -1) {
            layer.msg(data.msg, {icon: 5})
        }else if (data.code == -2) {
            layer.msg(data.msg, {icon: 5})
        }else {
            layer.msg("未知异常，请联系开发人员！", {icon: 5})
        }
    }, function (error) {

    })

})